package com.ctrip.demo.leetcode;

import java.util.ArrayList;
import java.util.List;

public class LeetCode2100 {

    public static void main(String[] args) {

        System.out.println(goodDaysToRobBank(new int[]{5,3,3,3,5,6,2}, 2));

    }


    public static List<Integer> goodDaysToRobBank(int[] security, int time) {

        List<Integer> res = new ArrayList<>();

        int[] arr1 = helper1(security);
        int[] arr2 = helper2(security);

        for (int i = 0; i < arr1.length; i++) {
            if (arr1[i] >= time && arr2[i] >= time) {
                res.add(i);
            }
        }

        return res;
    }

    /**
     * 非递增数目
     * @param security
     * @return
     */
    private static int[] helper1(int[] security) {
        int[] arr = new int[security.length];
        for (int i = 1; i < arr.length; i++) {
            if (security[i] > security[i - 1]) {
                arr[i] = 0;
            } else {
                arr[i] = arr[i - 1] + 1;
            }
        }
        return arr;
    }
    /**
     * 非递减数目
     * @param security
     * @return
     */
    private static int[] helper2(int[] security) {
        int[] arr = new int[security.length];
        for (int i = arr.length - 1; i > 0; i--) {
            if (security[i] < security[i - 1]) {
                arr[i - 1] = 0;
            } else {
                arr[i - 1] = arr[i] + 1;
            }
        }
        return arr;
    }
}
